/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.buaa.act.gephi.plugin.gui;

import static edu.buaa.act.gephi.plugin.gui.PluginStatus.*;
import static edu.buaa.act.gephi.plugin.task.Traverse.pathLength2Str;
import static edu.buaa.act.gephi.plugin.task.Traverse.timePeriod2Str;

//import edu.buaa.act.gephi.plugin.preview.HeatMapStatisticPreview;
import edu.buaa.act.gephi.plugin.exception.BackgroundTaskErrorHandler;
import edu.buaa.act.gephi.plugin.preview.HeatMapStatisticPreview;
import edu.buaa.act.gephi.plugin.task.*;
import edu.buaa.act.gephi.plugin.tool.TimeDependentPathTool;
import edu.buaa.act.gephi.plugin.utils.GUIHook;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JSlider;
import javax.swing.JSpinner.DateEditor;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;

import edu.buaa.act.gephi.plugin.utils.TGraphFileView;
import org.act.neo4j.temporal.demo.utils.Helper;

import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.project.api.ProjectController;
import org.gephi.utils.longtask.api.LongTaskExecutor;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.util.Lookup;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(
        dtd = "-//edu.buaa.act.gephi.plugin.gui//TGraphDemoPanelTopComponent//EN",
        autostore = false
)
@TopComponent.Description(
        preferredID = "TGraphDemoPanelTopComponent",
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "rankingmode", openAtStartup = false)
@ActionID(category = "Window", id = "edu.buaa.act.gephi.plugin.gui.TGraphDemoPanelTopComponent")
@ActionReference(path = "Menu/Plugins" , position = 7333)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_TGraphDemoPanelAction",
        preferredID = "TGraphDemoPanelTopComponent"
)
@Messages({
    "CTL_TGraphDemoPanelAction=TGraph Demo",
    "CTL_TGraphDemoPanelTopComponent=TGraph Demo",
    "HINT_TGraphDemoPanelTopComponent=Demonstration of TGraph DataBase: Traffic Data example."
})
public final class TGraphDemoPanelTopComponent extends TopComponent {

    private GraphDatabaseService db;
    private String dbPath;
    private PluginStatus status=INIT;
    private int totalNodeCount = 0;
    private int totalEdgeCount = 0;
    private int graphMinTime = 0;
    private int graphMaxTime = 0;


    public TGraphDemoPanelTopComponent() {
        initComponents();
        System.out.println("TopComponent init...");
        setName(Bundle.CTL_TGraphDemoPanelTopComponent());
        setToolTipText(Bundle.HINT_TGraphDemoPanelTopComponent());
        putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, Boolean.TRUE);
        setUIStatus(INIT);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        TabbedPane_content = new javax.swing.JTabbedPane();
        Tab_import = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        Button_import = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        List_subGraph = new javax.swing.JList();
        Button_findSubGraph = new javax.swing.JButton();
        Label_subGraphCount = new javax.swing.JLabel();
        Slider_importSpeed = new javax.swing.JSlider();
        Label_importSpeed = new javax.swing.JLabel();
        CheckBox_isDirectGraph = new javax.swing.JCheckBox();
        Tab_pathFinding = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        ComboBox_algorithms = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        ToggleButton_chooseStartNode = new javax.swing.JToggleButton();
        Label_startNode = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        ToggleButton_chooseEndNode = new javax.swing.JToggleButton();
        Label_endNode = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        Slider_startTime = new javax.swing.JSlider();
        Spinner_startTime = new javax.swing.JSpinner();
        Button_runControl = new javax.swing.JButton();
        Panel_resultColor = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        Button_clearAllPath = new javax.swing.JButton();
        Tab_pathFinding1 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        Spinner_time = new javax.swing.JSpinner();
        Slider_time = new javax.swing.JSlider();
        Label_refreshTaskStatus = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        Tab_heatMap = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        Spinner_HeatMapStartTime = new javax.swing.JSpinner();
        Slider_HeatMapStartTime = new javax.swing.JSlider();
        Slider_winSize = new javax.swing.JSlider();
        jLabel7 = new javax.swing.JLabel();
        Slider_ShadowSize = new javax.swing.JSlider();
        jLabel8 = new javax.swing.JLabel();
        Label_winSize = new javax.swing.JLabel();
        Label_shadowSize = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        Slider_HeatMapScale = new javax.swing.JSlider();
        jLabel10 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        Button_connect = new javax.swing.JButton();
        Label_dbInfo = new javax.swing.JLabel();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel2.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(Button_import, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Button_import.text")); // NOI18N
        Button_import.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Button_importMouseClicked(evt);
            }
        });

        List_subGraph.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {};
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(List_subGraph);

        Button_findSubGraph.setLabel(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Button_findSubGraph.label")); // NOI18N
        Button_findSubGraph.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Button_findSubGraphMouseClicked(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(Label_subGraphCount, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_subGraphCount.text")); // NOI18N

        Slider_importSpeed.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_importSpeedStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(Label_importSpeed, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_importSpeed.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(CheckBox_isDirectGraph, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.CheckBox_isDirectGraph.text")); // NOI18N

        javax.swing.GroupLayout Tab_importLayout = new javax.swing.GroupLayout(Tab_import);
        Tab_import.setLayout(Tab_importLayout);
        Tab_importLayout.setHorizontalGroup(
            Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_importLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(Tab_importLayout.createSequentialGroup()
                        .addComponent(Button_import)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CheckBox_isDirectGraph)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Slider_importSpeed, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Tab_importLayout.createSequentialGroup()
                                .addComponent(Label_importSpeed)
                                .addGap(37, 37, 37))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Tab_importLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Label_subGraphCount)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                        .addComponent(Button_findSubGraph)))
                .addContainerGap())
        );
        Tab_importLayout.setVerticalGroup(
            Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_importLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(Button_findSubGraph)
                    .addComponent(Label_subGraphCount))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Tab_importLayout.createSequentialGroup()
                        .addGroup(Tab_importLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Button_import)
                            .addComponent(CheckBox_isDirectGraph))
                        .addContainerGap(18, Short.MAX_VALUE))
                    .addGroup(Tab_importLayout.createSequentialGroup()
                        .addComponent(Slider_importSpeed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Label_importSpeed)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        TabbedPane_content.addTab(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Tab_import.TabConstraints.tabTitle"), Tab_import); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel3.text")); // NOI18N

        ComboBox_algorithms.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel4.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(ToggleButton_chooseStartNode, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.ToggleButton_chooseStartNode.text")); // NOI18N
        ToggleButton_chooseStartNode.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ToggleButton_chooseStartNodeItemStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(Label_startNode, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_startNode.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel6.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(ToggleButton_chooseEndNode, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.ToggleButton_chooseEndNode.text")); // NOI18N
        ToggleButton_chooseEndNode.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ToggleButton_chooseEndNodeItemStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(Label_endNode, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_endNode.text")); // NOI18N

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jPanel4.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        Slider_startTime.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_startTimeStateChanged(evt);
            }
        });

        Spinner_startTime.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(1305422940000L), new java.util.Date(1305422820000L), new java.util.Date(1463275763123L), java.util.Calendar.HOUR));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Spinner_startTime, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(Slider_startTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(Slider_startTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(Spinner_startTime, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        org.openide.awt.Mnemonics.setLocalizedText(Button_runControl, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Button_runControl.text_1")); // NOI18N
        Button_runControl.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Button_findShortestPathMouseClicked(evt);
            }
        });

        Panel_resultColor.setBackground(new java.awt.Color(255, 0, 51));
        Panel_resultColor.setToolTipText(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Panel_resultColor.toolTipText")); // NOI18N
        Panel_resultColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Panel_resultColorMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout Panel_resultColorLayout = new javax.swing.GroupLayout(Panel_resultColor);
        Panel_resultColor.setLayout(Panel_resultColorLayout);
        Panel_resultColorLayout.setHorizontalGroup(
            Panel_resultColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );
        Panel_resultColorLayout.setVerticalGroup(
            Panel_resultColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel5.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(Button_clearAllPath, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Button_clearAllPath.text_1")); // NOI18N
        Button_clearAllPath.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Button_clearAllPathMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout Tab_pathFindingLayout = new javax.swing.GroupLayout(Tab_pathFinding);
        Tab_pathFinding.setLayout(Tab_pathFindingLayout);
        Tab_pathFindingLayout.setHorizontalGroup(
            Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_pathFindingLayout.createSequentialGroup()
                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(Tab_pathFindingLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, Tab_pathFindingLayout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ComboBox_algorithms, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, Tab_pathFindingLayout.createSequentialGroup()
                                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6))
                                .addGap(18, 18, 18)
                                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(Label_endNode)
                                    .addComponent(Label_startNode))
                                .addGap(35, 35, 35)
                                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(ToggleButton_chooseStartNode)
                                    .addComponent(ToggleButton_chooseEndNode)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, Tab_pathFindingLayout.createSequentialGroup()
                                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(Tab_pathFindingLayout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Panel_resultColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(Button_clearAllPath))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(Button_runControl)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        Tab_pathFindingLayout.setVerticalGroup(
            Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_pathFindingLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(ComboBox_algorithms, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(Label_startNode)
                        .addComponent(ToggleButton_chooseStartNode, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(7, 7, 7)
                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(Label_endNode)
                        .addComponent(ToggleButton_chooseEndNode, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Panel_resultColor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(Tab_pathFindingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button_clearAllPath)
                    .addComponent(Button_runControl))
                .addContainerGap())
        );

        TabbedPane_content.addTab(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Tab_pathFinding.TabConstraints.tabTitle"), Tab_pathFinding); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jPanel5.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        Spinner_time.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(1305422940000L), new java.util.Date(1305422820000L), new java.util.Date(1463275763123L), java.util.Calendar.HOUR));

        Slider_time.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_timeStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(Label_refreshTaskStatus, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_refreshTaskStatus.text")); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Slider_time, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Spinner_time, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(Label_refreshTaskStatus)
                .addGap(28, 28, 28))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(Slider_time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Spinner_time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Label_refreshTaskStatus))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jPanel10.border.title"))); // NOI18N

        jPanel2.setBackground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        org.openide.awt.Mnemonics.setLocalizedText(jLabel11, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel11.text")); // NOI18N

        jPanel8.setBackground(new java.awt.Color(51, 51, 51));

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        org.openide.awt.Mnemonics.setLocalizedText(jLabel15, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel15.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel14, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel14.text")); // NOI18N

        jPanel9.setBackground(new java.awt.Color(0, 51, 255));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel3.setBackground(new java.awt.Color(255, 153, 51));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        org.openide.awt.Mnemonics.setLocalizedText(jLabel12, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel12.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel13, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel13.text")); // NOI18N

        jPanel7.setBackground(new java.awt.Color(0, 204, 0));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addGap(28, 28, 28)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel11))
                    .addComponent(jLabel12)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel13)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout Tab_pathFinding1Layout = new javax.swing.GroupLayout(Tab_pathFinding1);
        Tab_pathFinding1.setLayout(Tab_pathFinding1Layout);
        Tab_pathFinding1Layout.setHorizontalGroup(
            Tab_pathFinding1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_pathFinding1Layout.createSequentialGroup()
                .addGroup(Tab_pathFinding1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 4, Short.MAX_VALUE))
        );
        Tab_pathFinding1Layout.setVerticalGroup(
            Tab_pathFinding1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_pathFinding1Layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        TabbedPane_content.addTab(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Tab_pathFinding1.TabConstraints.tabTitle"), Tab_pathFinding1); // NOI18N

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jPanel6.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        Spinner_HeatMapStartTime.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(1305422940000L), new java.util.Date(1305422820000L), new java.util.Date(1463275763123L), java.util.Calendar.HOUR));
        Spinner_HeatMapStartTime.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Spinner_HeatMapStartTimeStateChanged(evt);
            }
        });

        Slider_HeatMapStartTime.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_HeatMapStartTimeStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Slider_HeatMapStartTime, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Spinner_HeatMapStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(Slider_HeatMapStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Spinner_HeatMapStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        Slider_winSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_winSizeStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel7.text")); // NOI18N

        Slider_ShadowSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_ShadowSizeStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel8.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(Label_winSize, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_winSize.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(Label_shadowSize, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_shadowSize.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel9, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel9.text")); // NOI18N

        Slider_HeatMapScale.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                Slider_HeatMapScaleStateChanged(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel10.text")); // NOI18N

        javax.swing.GroupLayout Tab_heatMapLayout = new javax.swing.GroupLayout(Tab_heatMap);
        Tab_heatMap.setLayout(Tab_heatMapLayout);
        Tab_heatMapLayout.setHorizontalGroup(
            Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_heatMapLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 4, Short.MAX_VALUE))
            .addGroup(Tab_heatMapLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Slider_winSize, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Slider_ShadowSize, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(Tab_heatMapLayout.createSequentialGroup()
                        .addGroup(Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(Tab_heatMapLayout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(Label_shadowSize))
                            .addGroup(Tab_heatMapLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Label_winSize)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(Slider_HeatMapScale, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(Tab_heatMapLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel10)))
                .addContainerGap())
        );
        Tab_heatMapLayout.setVerticalGroup(
            Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Tab_heatMapLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(Label_winSize))
                .addGap(3, 3, 3)
                .addComponent(Slider_winSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Label_shadowSize)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Slider_ShadowSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(Tab_heatMapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Slider_HeatMapScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        TabbedPane_content.addTab(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Tab_heatMap.TabConstraints.tabTitle"), Tab_heatMap); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.jLabel1.text")); // NOI18N

        Button_connect.setLabel(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Button_connect.label")); // NOI18N
        Button_connect.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Button_connectMouseClicked(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(Label_dbInfo, org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.Label_dbInfo.text")); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Label_dbInfo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(Button_connect)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(TabbedPane_content, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 1, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button_connect)
                    .addComponent(Label_dbInfo)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TabbedPane_content, javax.swing.GroupLayout.PREFERRED_SIZE, 274, Short.MAX_VALUE))
        );

        TabbedPane_content.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TGraphDemoPanelTopComponent.class, "TGraphDemoPanelTopComponent.TabbedPane_content.AccessibleContext.accessibleName")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 65, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(147, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void Button_connectMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Button_connectMouseClicked
        if(status==INIT){
            JFileChooser jFileChooser = new JFileChooser();
            jFileChooser.setFileView(new TGraphFileView());
            jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            final File dbDir;
            if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                dbDir = jFileChooser.getSelectedFile();
                if (dbDir.exists()) {
//                    db = getTGraphInstance(dbDir.getAbsolutePath());

                    GetTGraphDatabaseInfoAsyncTask connectTask = new GetTGraphDatabaseInfoAsyncTask(dbDir);
                    connectTask.onFinish(new GUIHook<Map<String, Object>>() {
                        @Override
                        public void guiHandler(Map<String, Object> value) {
                            if (value != null) {
                                Label_dbInfo.setText(
                                        "nodes:" + value.get("node-count") + " edges:" + value.get("edge-count")
                                );
                                totalNodeCount = (Integer) value.get("node-count");
                                totalEdgeCount = (Integer) value.get("edge-count");
                                graphMinTime =  (Integer) value.get("graph-min-time");
                                graphMaxTime =  (Integer) value.get("graph-max-time");
                                db = (GraphDatabaseService) value.get("db-instance");
                                dbPath = dbDir.getAbsolutePath();
                                setUIStatus(DB_READY);
                                final FindSeparateSubGraphAsyncTask subgraphTask = new FindSeparateSubGraphAsyncTask(db, totalNodeCount);
                                subgraphTask.onFinish(new GUIHook<List<FindSeparateSubGraphAsyncTask.IsolatedNetworkInfo>>(){
                                    public void guiHandler(List<FindSeparateSubGraphAsyncTask.IsolatedNetworkInfo> value) {
                                        DefaultListModel model = new DefaultListModel();
                                        for(FindSeparateSubGraphAsyncTask.IsolatedNetworkInfo info: value){
                                            model.addElement(info.getNodeCount()+" nodes. Start node id "+info.getStartNodeId());
                                        }
                                        List_subGraph.setVisibleRowCount(7);
                                        List_subGraph.setModel(model);
                                        Label_subGraphCount.setText(value.size()+" found");
                                        setUIStatus(SUBNET_FOUND);
                                    }
                                });
                                new LongTaskExecutor(true).execute(subgraphTask, subgraphTask, "Find Unconnected subgraphs...", null);

                                HeatMapStatisticPreview preview = Lookup.getDefault().lookup(HeatMapStatisticPreview.class);
                                preview.setDB(db);
                            }
                        }
                    });
                    Button_connect.setEnabled(false);
                    new LongTaskExecutor(true).execute(connectTask, connectTask, "connecting...", null);
                } else {
                    notice("dir not found!");
                }
            }
        }else{
            if(confirm("Disconnect from TGraph?")){
                Button_connect.setEnabled(false);
                DatabaseShutDownAsyncTask task = new DatabaseShutDownAsyncTask(db){
                    @Override
                    public void onFinish(){
                        new GUIHook<Object>(){
                            @Override
                            public void guiHandler(Object value) {
                                db=null;
                                dbPath=null;
                                setUIStatus(INIT);
                            }
                        }.guiHandler(null);
                    }
                };
                new LongTaskExecutor(false).execute(task,task,"Shutting Down...", BackgroundTaskErrorHandler.instance());
            }
        }
    }//GEN-LAST:event_Button_connectMouseClicked

    private void Button_findSubGraphMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Button_findSubGraphMouseClicked
        if(status.value()>= DB_READY.value()){
            FindSeparateSubGraphAsyncTask task = new FindSeparateSubGraphAsyncTask(db, totalNodeCount);
            task.onFinish(new GUIHook<List<FindSeparateSubGraphAsyncTask.IsolatedNetworkInfo>>(){
                public void guiHandler(List<FindSeparateSubGraphAsyncTask.IsolatedNetworkInfo> value) {
                    DefaultListModel model = new DefaultListModel();
                    for(FindSeparateSubGraphAsyncTask.IsolatedNetworkInfo info: value){
                        model.addElement(info.getNodeCount()+" nodes. Start node id "+info.getStartNodeId());
                    }
                    List_subGraph.setVisibleRowCount(7);
                    List_subGraph.setModel(model);
                    Label_subGraphCount.setText(value.size()+" found");
                    setUIStatus(SUBNET_FOUND);
                }
            });
            new LongTaskExecutor(true).execute(task, task,"Find Unconnected subgraphs...",null);
        }else{
            notice("Please connect to TGraph database first.");
        }
    }//GEN-LAST:event_Button_findSubGraphMouseClicked

    private NetworkImportAsyncTask netImportTask;
    private void Button_importMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Button_importMouseClicked
        if(status.value()>=SUBNET_FOUND.value()){
            String selectText = (String) List_subGraph.getSelectedValue();
            if(selectText!=null){
                ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
                if (pc.getCurrentProject() == null) {
                    notice("no project");
                }
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                long nodeId = Long.valueOf(selectText.substring(selectText.lastIndexOf(" ")+1,selectText.length()));
                int nodeCount = Integer.valueOf(selectText.substring(0,selectText.indexOf(" ")));
//                System.out.println(nodeId+" "+nodeCount);
                netImportTask = new NetworkImportAsyncTask(
                        db,
                        gc.getGraphModel(),
                        nodeId,
                        nodeCount,
                        Slider_importSpeed.getValue()/10f,
                        CheckBox_isDirectGraph.isSelected()                        
                );
                netImportTask.onFinish(new GUIHook<Integer>(){
                    public void guiHandler(Integer value) {
                        notice("import "+value+" nodes");
                        setUIStatus(NET_IMPORTED);
                    }
                });
                new LongTaskExecutor(true).execute(netImportTask,netImportTask,"importing...",null);
            }else{
                notice("Pleae select subgraph to import.");
            }
        }else{
            notice("should find subgraph first.");
        }
    }//GEN-LAST:event_Button_importMouseClicked

    private int realTimeFormatConvert(Date t){
        Calendar time = Calendar.getInstance();
        time.setTime(t);
        int month = time.get(Calendar.MONTH);
        int day = time.get(Calendar.DAY_OF_MONTH);
        int hour = time.get(Calendar.HOUR_OF_DAY);
        int minute = time.get(Calendar.MINUTE);
        String timeStr = "11"+String.format("%02d",month)+
                String.format("%02d",day)+String.format("%02d",hour)+
                String.format("%02d",minute);
        return Integer.parseInt(timeStr);
    }
    
    private int dateTimeConvert(Date t){
        long t0 = t.getTime();
        return (int) (t0/1000);
    }
    
    private String time2String(int t){
        return t+"";
    }
    
    private void Button_findShortestPathMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Button_findShortestPathMouseClicked
        SpinnerModel model = Spinner_startTime.getModel();
        if(model instanceof SpinnerDateModel){
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            long startNodeTGraphId = (Long) startNode.getAttribute("tgraph_id");
            long endNodeTGraphId = (Long) endNode.getAttribute("tgraph_id");
            int time = dateTimeConvert(((SpinnerDateModel) model).getDate());
            String algorithms = (String)ComboBox_algorithms.getSelectedItem();
            Traverse task;
//            TimeDependentDijkstraOneTransactionAsyncTask task;

            Traverse.GUICallBack callback = new Traverse.GUICallBack() {
                @Override
                public void onResult(long searchNodeCount, List<Long> path, List<Integer> arriveTimes, int pathRealLength) {
                    int arriveTime = arriveTimes.get(arriveTimes.size() - 1);
                    int startTime = arriveTimes.get(0);
                    String result = "Path found! Search " + searchNodeCount + " nodes.\n" +
                            "Departure at: " + Helper.timeStamp2String(startTime) + "\n" +
                            "  Arrive  at: " + Helper.timeStamp2String(arriveTime) + "\n" +
                            "   Time Cost: " + timePeriod2Str(arriveTime - startTime) + "\n" +
                            "      length: " + pathLength2Str(pathRealLength);
                    System.out.println(result);
                    notice(result);
                }
            };

            if("Time Dependent Dijkstra".equals(algorithms)) {
                task = new TimeDependentDijkstraOneTransactionAsyncTask(
                        db,
                        gc.getGraphModel(),
                        startNodeTGraphId,
                        endNodeTGraphId,
                        time,
                        Panel_resultColor.getBackground(),
                        callback);
//            }else{
            }else if("Dijkstra".equals(algorithms)){
                task =  new DijkstraOneTransactionAsyncTask(
                        db,
                        gc.getGraphModel(),
                        startNodeTGraphId,
                        endNodeTGraphId,
                        time,
                        Panel_resultColor.getBackground(),
                        callback);
            }else{
                task =  new ReachableAreaVisualizationAsyncTask(
                        db,
                        gc.getGraphModel(),
                        startNodeTGraphId,
                        endNodeTGraphId,
                        time,
                        Panel_resultColor.getBackground());
            }
            new LongTaskExecutor(true).execute(task, task);
        }
    }//GEN-LAST:event_Button_findShortestPathMouseClicked

    private void ToggleButton_chooseStartNodeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ToggleButton_chooseStartNodeItemStateChanged
        TimeDependentPathTool tool = Lookup.getDefault().lookup(TimeDependentPathTool.class);
        if(evt.getStateChange()==ItemEvent.SELECTED){
            if(tool.setUIStatus("start")){
                setUIStatus(CHOOSING_START);
            }else{
                ToggleButton_chooseStartNode.setSelected(false);
                notice("Please press tool icon first.");
            }
        }else{
            setUIStatus(NET_IMPORTED);
            startNode = tool.getStartNode();
            if(startNode!=null){
                Label_startNode.setText("node["+startNode.getAttribute("tgraph_id")+"]");                
            }else{
                notice("start node not selected.");
            }
        }
    }//GEN-LAST:event_ToggleButton_chooseStartNodeItemStateChanged

    private void ToggleButton_chooseEndNodeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ToggleButton_chooseEndNodeItemStateChanged
        TimeDependentPathTool tool = Lookup.getDefault().lookup(TimeDependentPathTool.class);
        if(evt.getStateChange()==ItemEvent.SELECTED){
            if(tool.setUIStatus("end")){
                setUIStatus(CHOOSING_END);
            }else{
                ToggleButton_chooseEndNode.setSelected(false);
                notice("Please press tool icon first.");
            }
        }else{
            setUIStatus(NET_IMPORTED);
            endNode = tool.getEndNode();
            if(endNode!=null){
                Label_endNode.setText("node["+endNode.getAttribute("tgraph_id")+"]");                
            }else{
                notice("end node not selected.");
            }
        }
    }//GEN-LAST:event_ToggleButton_chooseEndNodeItemStateChanged

    private void Slider_importSpeedStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_importSpeedStateChanged
        JSlider source = (JSlider)evt.getSource();
        if (!source.getValueIsAdjusting()) { // when dragging: do nothing; when release: go following lines.
            int speed = (int)source.getValue();
            Label_importSpeed.setText("Speed: "+(speed/10f)+"x");
            if(netImportTask!=null){
                netImportTask.setImportSpeed(speed / 10f);
            }
        }
    }//GEN-LAST:event_Slider_importSpeedStateChanged

    private void Slider_timeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_timeStateChanged
        JSlider source = (JSlider)evt.getSource();
        int timeStamp = Slider_time.getValue();
        if (source.getValueIsAdjusting()) { // when dragging: only update time label
            Date time = new Date(timeStamp*1000L);
            trafficStatusTimeModel.setValue(time);
        }else if(status.value()>INIT.value()){// when release: start connectTask.
            Label_refreshTaskStatus.setText("updating...");
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            UpdateGraphStatusAsyncTask task = new UpdateGraphStatusAsyncTask(db,gc.getGraphModel().getGraph(),timeStamp);
            task.onFinish(new GUIHook<Integer>(){
                public void guiHandler(Integer value) {
                    Label_refreshTaskStatus.setText("done");
                }
            });
            new LongTaskExecutor(true).execute(task,task,"refreshing...",null);
        }
    }//GEN-LAST:event_Slider_timeStateChanged

    private void Panel_resultColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Panel_resultColorMouseClicked
        Color newColor = JColorChooser.showDialog(this, "Choose Color of Shortest Path", Panel_resultColor.getBackground());
        if(newColor!=null){
            Panel_resultColor.setBackground(newColor);
        }
    }//GEN-LAST:event_Panel_resultColorMouseClicked

    private void Slider_startTimeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_startTimeStateChanged
        JSlider source = (JSlider)evt.getSource();
        int timeStamp = Slider_startTime.getValue();
        if (source.getValueIsAdjusting()) { // when dragging: only update time label
            Date time = new Date(timeStamp*1000L);
            pathSearchStartTimeModel.setValue(time);
        }
    }//GEN-LAST:event_Slider_startTimeStateChanged

    
    private void Slider_HeatMapStartTimeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_HeatMapStartTimeStateChanged
        JSlider source = (JSlider)evt.getSource();
        int timeStamp = Slider_HeatMapStartTime.getValue();
        if (status.value()>INIT.value()) { // not an init event.
            if(!source.getValueIsAdjusting()){ // when release: set value to preview.
                HeatMapStatisticPreview preview = Lookup.getDefault().lookup(HeatMapStatisticPreview.class);
                preview.setStartTime(timeStamp);
            }
        }
        Date time = new Date(timeStamp*1000L);
        heatMapStartTimeModel.setValue(time);
    }//GEN-LAST:event_Slider_HeatMapStartTimeStateChanged

    private void Slider_winSizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_winSizeStateChanged
        JSlider source = (JSlider)evt.getSource();
        int winSize = Slider_winSize.getValue();
        if(status.value()>INIT.value()){// not an init event.
            if(!source.getValueIsAdjusting()){ // when release: set value to preview.
                HeatMapStatisticPreview preview = Lookup.getDefault().lookup(HeatMapStatisticPreview.class);
                preview.setWindowSize(winSize*60);
            }
        }
        Label_winSize.setText(timePeroid2Str(winSize));
    }//GEN-LAST:event_Slider_winSizeStateChanged

    private void Slider_ShadowSizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_ShadowSizeStateChanged
        JSlider source = (JSlider)evt.getSource();
        int shadowSize = Slider_ShadowSize.getValue();
        if(status.value()>INIT.value()){// not an init event.
            if(!source.getValueIsAdjusting()){ // when release: set value to preview.
                HeatMapStatisticPreview preview = Lookup.getDefault().lookup(HeatMapStatisticPreview.class);
                preview.setShadowSize(shadowSize);
            }
        }
        Label_shadowSize.setText(String.format("%dm", shadowSize));
    }//GEN-LAST:event_Slider_ShadowSizeStateChanged

    private void Button_clearAllPathMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Button_clearAllPathMouseClicked
        GraphController gc = Lookup.getDefault().lookup(GraphController.class);
        ClearAllPathAsyncTask task = new ClearAllPathAsyncTask(gc.getGraphModel().getGraph());
        new LongTaskExecutor(false).execute(task, task, "Clearing all Path...", BackgroundTaskErrorHandler.instance());
    }//GEN-LAST:event_Button_clearAllPathMouseClicked

    private void Slider_HeatMapScaleStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Slider_HeatMapScaleStateChanged
        JSlider source = (JSlider)evt.getSource();
        int scale = Slider_HeatMapScale.getValue();
        if(status.value()>INIT.value()){// not an init event.
            if(!source.getValueIsAdjusting()){ // when release: set value to preview.
                HeatMapStatisticPreview preview = Lookup.getDefault().lookup(HeatMapStatisticPreview.class);
                preview.setImageScale(scale);
            }
        }
    }//GEN-LAST:event_Slider_HeatMapScaleStateChanged

    private void Spinner_HeatMapStartTimeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_Spinner_HeatMapStartTimeStateChanged
        SpinnerDateModel model = (SpinnerDateModel) Spinner_HeatMapStartTime.getModel();
        Slider_HeatMapStartTime.setValue(dateTimeConvert(model.getDate()));
    }//GEN-LAST:event_Spinner_HeatMapStartTimeStateChanged

    private Node startNode;
    private Node endNode;
    public void onNodeClick(Node[] nodes, String status){
        if(nodes.length>0){
            setUIStatus(NET_IMPORTED);
            if(status.equals("start")){
                startNode = nodes[0];
                Label_startNode.setText("node["+startNode.getAttribute("tgraph_id")+"]");
            }else if(status.equals("end")){
                endNode = nodes[0];
                Label_endNode.setText("node["+endNode.getAttribute("tgraph_id")+"]");
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Button_clearAllPath;
    private javax.swing.JButton Button_connect;
    private javax.swing.JButton Button_findSubGraph;
    private javax.swing.JButton Button_import;
    private javax.swing.JButton Button_runControl;
    private javax.swing.JCheckBox CheckBox_isDirectGraph;
    private javax.swing.JComboBox ComboBox_algorithms;
    private javax.swing.JLabel Label_dbInfo;
    private javax.swing.JLabel Label_endNode;
    private javax.swing.JLabel Label_importSpeed;
    private javax.swing.JLabel Label_refreshTaskStatus;
    private javax.swing.JLabel Label_shadowSize;
    private javax.swing.JLabel Label_startNode;
    private javax.swing.JLabel Label_subGraphCount;
    private javax.swing.JLabel Label_winSize;
    private javax.swing.JList List_subGraph;
    private javax.swing.JPanel Panel_resultColor;
    private javax.swing.JSlider Slider_HeatMapScale;
    private javax.swing.JSlider Slider_HeatMapStartTime;
    private javax.swing.JSlider Slider_ShadowSize;
    private javax.swing.JSlider Slider_importSpeed;
    private javax.swing.JSlider Slider_startTime;
    private javax.swing.JSlider Slider_time;
    private javax.swing.JSlider Slider_winSize;
    private javax.swing.JSpinner Spinner_HeatMapStartTime;
    private javax.swing.JSpinner Spinner_startTime;
    private javax.swing.JSpinner Spinner_time;
    private javax.swing.JPanel Tab_heatMap;
    private javax.swing.JPanel Tab_import;
    private javax.swing.JPanel Tab_pathFinding;
    private javax.swing.JPanel Tab_pathFinding1;
    private javax.swing.JTabbedPane TabbedPane_content;
    private javax.swing.JToggleButton ToggleButton_chooseEndNode;
    private javax.swing.JToggleButton ToggleButton_chooseStartNode;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened() {
        if(dbPath==null || db==null){
            setUIStatus(INIT);
        }
    }

    @Override
    public void componentClosed() {
        System.out.println("component close");
//        if(confirm("Disconnect from TGraph?")){
//            if(db!=null) db.shutdown();
//            db=null;
//            dbPath=null;
//            setUIStatus(INIT);
//        }
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
    
    private void notice(String s) {
        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(s));
    }
    
    private boolean confirm(String s){
        return DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation(s, NotifyDescriptor.OK_CANCEL_OPTION)) == NotifyDescriptor.OK_OPTION;
    }
    
    private GraphDatabaseService getTGraphInstance(String absolutePath) {
        if (db == null) {
            dbPath = absolutePath;
            db = new GraphDatabaseFactory()
                    .newEmbeddedDatabaseBuilder(absolutePath)
                    .loadPropertiesFromFile("")
                    .newGraphDatabase();
        }
        return db;
    }


    SpinnerDateModel pathSearchStartTimeModel;
    SpinnerDateModel trafficStatusTimeModel;
    SpinnerDateModel heatMapStartTimeModel;
    private void setUIStatus(PluginStatus status){
        this.status = status;
        System.out.println(this.status);
        switch(status){
            case INIT:
                Label_dbInfo.setText("not connected.");
                Button_connect.setText("Connect");
                Button_connect.setEnabled(true);
                Button_findSubGraph.setEnabled(false);
                Button_import.setEnabled(false);
                TabbedPane_content.setSelectedIndex(0);
                TabbedPane_content.setEnabled(false);
                setEnableAllChild(TabbedPane_content, false);
                List_subGraph.setModel(new javax.swing.AbstractListModel() {
                    public int getSize() {
                        return 0;
                    }

                    public Object getElementAt(int i) {
                        return null;
                    }
                });
                List_subGraph.setEnabled(false);
                Label_subGraphCount.setText("");
                ComboBox_algorithms.removeAllItems();
                ComboBox_algorithms.addItem("Time Dependent Dijkstra");
                ComboBox_algorithms.addItem("Reachable Area");
//                ComboBox_algorithms.addItem("Time Dependent A*");
//                ComboBox_algorithms.addItem("Time Dependent ALT");
                ComboBox_algorithms.addItem("Dijkstra");
                Slider_startTime.setMinimum(0);
                Slider_startTime.setMaximum(100);
                Label_startNode.setText("");
                Label_endNode.setText("");
                Slider_importSpeed.setMinimum(1);
                Slider_importSpeed.setMaximum(10);
                Button_findSubGraph.setVisible(false);
                Slider_winSize.setMinimum(1800);
                Slider_winSize.setMaximum(3600 * 24 * 30);
                Slider_winSize.setValue(3600);
                Slider_ShadowSize.setMinimum(50);
                Slider_ShadowSize.setMaximum(2000);
                Slider_ShadowSize.setValue(130);
                Slider_HeatMapScale.setMinimum(1);
                Slider_HeatMapScale.setMaximum(1000);
                Slider_HeatMapScale.setValue(1000);
                Slider_HeatMapScale.setVisible(false);
                jLabel10.setVisible(false);
                jLabel9.setVisible(false);
                break;
            case DB_READY:
                Button_connect.setText("Disconnect");
                Button_connect.setEnabled(true);
                Button_findSubGraph.setEnabled(true);
                Button_import.setEnabled(false);
                TabbedPane_content.setEnabled(true);
//                setEnableAllChild(Tab_import,true);
                Tab_pathFinding.setEnabled(false);
//                Calendar calendar = Calendar.getInstance();
//                calendar.set(2010,11-1,4,1,5);
                Date start = new Date(((long)graphMinTime)*1000);
//                calendar.set(2010,11-1,4,23,55);
                Date end = new Date(((long)graphMaxTime)*1000);
                // apply to path search start time selection.
                pathSearchStartTimeModel = new SpinnerDateModel(start,start,end, Calendar.MINUTE);
                pathSearchStartTimeModel.setCalendarField(Calendar.MINUTE);
                Spinner_startTime.setModel(pathSearchStartTimeModel);
                Spinner_startTime.setEditor(new DateEditor(Spinner_startTime, "yyyy-MM-dd HH:mm"));
                Slider_startTime.setMinimum(graphMinTime);
                Slider_startTime.setMaximum(graphMaxTime);
                Slider_startTime.setValue((graphMinTime+graphMaxTime)/2);
                // apply to traffic status time selection.
                trafficStatusTimeModel = new SpinnerDateModel(start,start,end, Calendar.MINUTE);
                Spinner_time.setModel(trafficStatusTimeModel);
                Spinner_time.setEditor(new DateEditor(Spinner_time, "yyyy-MM-dd HH:mm"));
                Slider_time.setMinimum(graphMinTime);
                Slider_time.setMaximum(graphMaxTime);
                Slider_time.setValue((graphMinTime+graphMaxTime)/2);
                // apply to heat map start time selection.
                heatMapStartTimeModel = new SpinnerDateModel(start,start,end, Calendar.MINUTE);
                Spinner_HeatMapStartTime.setModel(heatMapStartTimeModel);
                Spinner_HeatMapStartTime.setEditor(new DateEditor(Spinner_HeatMapStartTime, "yyyy-MM-dd HH:mm"));
                Slider_HeatMapStartTime.setMinimum(graphMinTime);
                Slider_HeatMapStartTime.setMaximum((graphMaxTime>graphMinTime+30)?(graphMaxTime-30):graphMaxTime);
                Slider_HeatMapStartTime.setValue((graphMinTime+graphMaxTime)/2);
                break;
            case SUBNET_FOUND:
                setEnableAllChild(Tab_import,true);
                List_subGraph.setEnabled(true);
                Button_import.setEnabled(true);
                break;
            case NET_IMPORTED://eg. ready for path finding.
//                TabbedPane_content.setEnabled(true);
                setEnableAllChild(TabbedPane_content, true);
                ToggleButton_chooseStartNode.setSelected(false);
                ToggleButton_chooseEndNode.setSelected(false);
                ToggleButton_chooseStartNode.setText("choose");
                ToggleButton_chooseEndNode.setText("choose");
                HeatMapStatisticPreview preview = Lookup.getDefault().lookup(HeatMapStatisticPreview.class);
                preview.setImageScale(Slider_HeatMapScale.getValue());
                preview.setShadowSize(Slider_ShadowSize.getValue());
                preview.setStartTime(Slider_HeatMapStartTime.getValue());
                preview.setWindowSize(Slider_winSize.getValue());
                break;
            case CHOOSING_START:
                ToggleButton_chooseStartNode.setText("done");
//                ToggleButton_chooseStartNode.
                break;
            case CHOOSING_END:
                ToggleButton_chooseEndNode.setText("done");
                break;
        }
    }

    private String timePeroid2Str(int timePeriod) { // unit: second
        if(timePeriod<24*3600){ // less than 1 day.
            return String.format("%.1f Hours",timePeriod/3600f);
        }else if(timePeriod<2*7*24*3600){ // less than 2 week.
            return String.format("%d Days %d Hours",
                    timePeriod/(24*3600),
                    (timePeriod%(24*3600))/3600);
        }else{ // larger than 2 week.
            return String.format("%d Week %d Days",
                    timePeriod/(7*24*3600),
                    (timePeriod%(7*24*3600))/(24*3600));
        }
    }
    
    private void setEnableAllChild(JComponent component, boolean enable){
        Component[] children = component.getComponents();
        for(Component child: children){
            if(child instanceof JComponent){
                setEnableAllChild(((JComponent) child), enable);
            }
            child.setEnabled(enable);
        }
    }
    
    
}
